<?php

namespace teach\service;

use Yii;

class Publicly
{
    /**
     * 查找其中一个用户
     * @param $where
     * @return array|false
     */
    public function userOne($where)
    {
        $sql = "SELECT * FROM edu_user WHERE {$where}";
        return Yii::$app->db->createCommand($sql)->queryOne();
    }

    /**
     * 商家分享，然后用户进行绑定
     * @param $map
     * @param $where
     * @return int
     */
    public function userBinding($map, $where)
    {
        $sql = "UPDATE edu_user SET {$map} WHERE {$where}";
        return Yii::$app->db->createCommand($sql)->execute();
    }

    /**
     * 增加一个下级记录
     * @param $map
     * @param $where
     * @return int
     */
    public function superiorAdd($map, $where)
    {
        $sql = "UPDATE edu_user SET {$map} WHERE {$where}";
        return Yii::$app->db->createCommand($sql)->execute();
    }

    /**
     * 统计订单数量
     * @param $whereStr
     * @return false|null|string
     */
    public function haveOrder($whereStr)
    {
        $sql = "SELECT COUNT(*) FROM mall_order WHERE  {$whereStr}";
        return Yii::$app->db->createCommand($sql)->queryScalar();
    }

    /**
     * 更新用户进入商城的时间
     * @param $map
     * @param $where
     * @return int
     */
    public function mallCreateTime($map, $where)
    {
        $sql = "UPDATE edu_user SET {$map} WHERE {$where}";
        return Yii::$app->db->createCommand($sql)->execute();
    }

    /**
     * 记录获取的积分
     * @param $map
     * @return mixed
     */
    public function scoreRecord($map)
    {
        return Yii::$app->db->createCommand()->insert('mall_score_record', $map)->execute();
    }

}